package www.wen.com.common.lib.base.module

import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.MutableLiveData
import www.wen.com.common.lib.data.repository.AppDataManager
import www.wen.com.common.lib.extension.verificationText

/**
 * @author WEN
 * @Description:
 * @date 2020/11/2 17:35
 */
open class BaseCountDownModel constructor(appDataManager: AppDataManager) : BaseApiViewModel(appDataManager), LifecycleObserver {

    val mTiming = MutableLiveData(0)

    val mEnabled = MutableLiveData(true)

    val mEnabledSubmit = MutableLiveData(false)

    val mVerificationCodeText = MutableLiveData(0.verificationText())

    val mVerificationCode = MutableLiveData("")

    val mPassWord = MutableLiveData("")

    val mPhone = MutableLiveData("")

    fun onVerificationCodeChanged(textChange: CharSequence) {
        switchEnabledSubmit(textChange)
    }

    fun onPasswordChanged(textChange: CharSequence) {
        switchEnabledSubmit(textChange)
    }

    fun enableSendVerificationCode(): Boolean {
        return mPhone.value!!.isNotBlank() &&
                mPhone.value!!.length >= 5 &&
                mTiming.value == 0
    }

    open fun switchEnabledSubmit(textChange: CharSequence) {}




}